<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>潮人电商后台</title>
    <link rel="stylesheet" href="css/style.css"/>
    <script type="text/javascript" src="/js/jquery.js"></script>
</head>
<body class="login_bg">
    <section class="loginBox">
        <header class="loginHeader">
            <h1>潮人管理系统</h1>
        </header>
        <section class="loginCont">
            <form  id="regist"  class="loginForm" action="welcome.html">
                <div class="inputbox">
                    <label for="user">用户名：</label>
                    <input id="user" type="text" name="uAccount" placeholder="请输入用户名"   onblur="verify(this)" required/>
                </div>
                <div class="inputbox">
                    <label for="mima">密码：</label>
                    <input id="mima" type="password" name="uPassword" placeholder="请输入密码" required/>
                </div>
                <div class="subBtn">
                    <input type="button" value="注册" onclick="regist()" />
                    <input type="button" value="登录" onclick="denglu()" />
                    <input type="reset" value="重置"/>
                </div>

            </form>
        </section>
    </section>


<script>

       function verify(ss) {

           var account = ss.value;

           $.ajax({

               url:"/queryAccount",
               type:"post",
               data:"uAccount="+account,
               success:function (data) {


                   if (data.code==0){
                       alert("账号可以注册");
                   }else{
                       if (data.code==5){

                        alert(data.msg);
                       }
                   }

               }
           })
       }

       function regist() {

            $.ajax({

                 url:"/registAccount",
                 type:"post",
                 data:$("#regist").serialize(),
                 success:function (data) {

                     if (data.code==1){
                         alert(data.msg);
                     }

                     if (data.code==0){
                         alert("注册成功");
                         location.href="http://localhost:8080/loginPage";
                     }else{
                         if (data.code==4){
                             alert(data.msg);
                         }
                     }
                 }
            })
       }


       function denglu() {

           if (confirm("即将跳转到登录页面")){

               location.href="http://localhost:8080/loginPage";
           }
       }
</script>
</body>
</html>